<?php

namespace app\index\service;

use app\index\dao\SourceCollectDao;
use app\index\model\UM as UM;
use ary\Ary;

/**
 * Class SourceCollectedService
 * @package app\index\service
 */
class SourceCollectedService
{
    // dao
    private SourceCollectDao $sourceCollectDao;
    private Ary $ary;

    public function __construct(SourceCollectDao $sourceCollectDao, Ary $ary)
    {
        $this->sourceCollectDao = $sourceCollectDao;
        $this->ary = $ary;
    }

    /**
     * 列表
     * @param UM $user
     * @param $params
     * @return array
     */
    public function index(UM $user, $params): array
    {
        ary_page($params);

        $memberId = $user->id;

        $ids = $this->sourceCollectDao->selectIdsByMemberId($memberId);

        if (empty($ids)) {
            return [];
        }

        $params['ids'] = implode(',', $ids);

        $response = $this->ary->getFavoriteList($params);

        $decodeContents = $response->getDecodeContents();

        return $decodeContents['data'];
    }

}
